using System.Windows;
using System;
using System.Windows.Input;
using System.Windows.Controls.Primitives;

namespace PSE.Framework.UI.Controls.SmartClient
{
    /// <summary>
    /// Controle GroupBox extendido para adicionar funcionalidades referentes a politicas de comportamento
    /// </summary>
    public class GroupBox : System.Windows.Controls.GroupBox
    {
        Button buttonClose = null;
        public readonly static RoutedUICommand Close = new RoutedUICommand();

        /// <summary>
        /// Construtor do objeto ScrollBar
        /// </summary>
        public GroupBox()
            : base()
        {
            //if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            //    return;

            CommandBindings.Add(new CommandBinding(GroupBox.Close, btnClose_Click));

        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            buttonClose = base.GetTemplateChild("ButtonClose") as Button;

        }

        #region INotifyPropertyChanged Members
        /// <summary>
        /// Evento da propriedade ao mudar a visibilidade
        /// </summary>
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region AllowClose
        public bool AllowClose
        {
            get { return (bool)GetValue(AllowCloseProperty); }
            set { SetValue(AllowCloseProperty, value); }
        }

        // Using a DependencyProperty as the backing store for AllowClose.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty AllowCloseProperty =
            DependencyProperty.Register("AllowClose", typeof(bool), typeof(GroupBox), new FrameworkPropertyMetadata(false));

        #endregion

        #region HeaderButtons

        public object HeaderButtons
        {
            get { return (object)GetValue(HeaderButtonsProperty); }
            set { SetValue(HeaderButtonsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HeaderButtons.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderButtonsProperty =
            DependencyProperty.Register("HeaderButtons", typeof(object), typeof(GroupBox), new FrameworkPropertyMetadata(null));


        public DataTemplate HeaderButtonsTemplate
        {
            get { return (DataTemplate)GetValue(HeaderButtonsTemplateProperty); }
            set { SetValue(HeaderButtonsTemplateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HeaderButtonsTemplate.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderButtonsTemplateProperty =
            DependencyProperty.Register("HeaderButtonsTemplate", typeof(DataTemplate), typeof(GroupBox), new FrameworkPropertyMetadata(null));


        #endregion

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            //if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            //    return;

            base.OnPropertyChanged(e);
            OnPropertyChanged(e.Property.Name);
        }

    }
}
